﻿using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using WMS.FC.Domain.DomainObject.System;
using WMS.FC.Domain.Service.Cell.Interface;
using WMS.FC.Domain.Service.System;

namespace WMS.FC.Domain.Service.Cell
{
    public class CheckCellBarcodeService : ServiceBase, ICheckCellBarcodeService
    {
        public CheckCellBarcodeService(ILogger<ServiceBase> logger, IOptions<WmsSettings> options, IMapper mapper) : base(logger, options, mapper)
        {
        }

        public async Task<ActionResultBase> CheckCellBarcode(string cellBarcode)
        {
            return await Task.Run(() =>
            {
                var result = new ActionResultBase("校验电池条码");
                try
                {
                    if (string.IsNullOrWhiteSpace(cellBarcode))
                        return result.ArgumentError("电池条码不能为空");

                    if (cellBarcode.Length != 24)
                        return result.ArgumentError("电池条码长度应为24位");
                }
                catch (Exception ex)
                {
                    return result.Exception(ex);
                }

                return result;
            });
        }
    }
}
